<html>
<head><meta charset="utf-8"><title>Soundness of Read implementation for &amp;File · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html">Soundness of Read implementation for &amp;File</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199730078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Soundness%20of%20Read%20implementation%20for%20%26File/near/199730078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Konrad Borowski <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html#199730078">(Jun 04 2020 at 10:54)</a>:</h4>
<p>I'm wondering about safety of <code>Read</code> implementation for <code>&amp;File</code><br>
The POSIX specification on <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html">https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html</a> says that "The behavior of multiple concurrent reads on the same pipe, FIFO, or terminal device is unspecified." (and our <code>Read</code> implementation on POSIX platforms pretty much calls <code>read</code>)<br>
I'm not sure whether "unspecified" here means UB, and whether it's an issue at all on all platforms we support (it may be something that POSIX doesn't specify, but all platforms we support do)</p>



<a name="199730334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Soundness%20of%20Read%20implementation%20for%20%26File/near/199730334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html#199730334">(Jun 04 2020 at 10:58)</a>:</h4>
<p>Unspecified behaviour is different from UB - see <a href="https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior">https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior</a></p>



<a name="199730464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Soundness%20of%20Read%20implementation%20for%20%26File/near/199730464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Konrad Borowski <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html#199730464">(Jun 04 2020 at 11:00)</a>:</h4>
<p>Yeah, but this isn't C specification, but rather POSIX, and in this case there is no "set of allowable behaviors" provided.</p>



<a name="199730962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Soundness%20of%20Read%20implementation%20for%20%26File/near/199730962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html#199730962">(Jun 04 2020 at 11:06)</a>:</h4>
<p>I would have assumed the set of allowable behaviours is implicitly "some bytes are provided" whether or not they look anything like the file they were supposed to have been read from</p>



<a name="199731006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Soundness%20of%20Read%20implementation%20for%20%26File/near/199731006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Konrad Borowski <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html#199731006">(Jun 04 2020 at 11:06)</a>:</h4>
<p>okay, that sounds reasonable</p>



<a name="199731057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Soundness%20of%20Read%20implementation%20for%20%26File/near/199731057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Konrad Borowski <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Soundness.20of.20Read.20implementation.20for.20.26File.html#199731057">(Jun 04 2020 at 11:07)</a>:</h4>
<p>so it's not UB, undesirable, sure, but as far Rust is concerned it's safe</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>